<?php

ptaste();

class ConfigHolder extends SiteObject
{

	var $cnf=array();
	
	function __construct($site,$logger=null,$file="")
	{
		parent::__construct($site,new JEngNullLogger());
		if ($file=="")
			$file=$_SERVER['DOCUMENT_ROOT']."/../config/jeng_config.xml";
		$this->process($file);
	}
	
	function process($file)
	{
		$xml=new DOMDocument();
		$xml->load($file);
		$root=$xml->documentElement;
		if ($root->nodeName!="jeng_config")
		  die("Error: bad configuration file");
		$cver=$root->getAttribute("version");
//		printf("config(%s) version=%d<br>\n",$file,$cver);
		$node=$root->firstChild;
		while($node)
		{
		  if ($node->nodeName=="param")
		  {
		    $pnm=$node->getAttribute("name");
			$pvl=$node->nodeValue;
//			printf("config(%s) add param %s=%s<br>\n",$file,$pnm,$pvl);
			$this->cnf[$pnm]=$pvl;
		  }
		  $node=$node->nextSibling;
		}
	}
	
	function get($name)
	{
		if (!$this->cnf[$name])
			return false;
		return $this->cnf[$name];
	}
	
	function set($name,$value)
	{
		$this->cnf[$name]=$value;
	}
	
	function has($name)
	{
	  return array_key_exists($name,$this->cnf);
	}
}

?>